package com.sharp.kernel.config.db;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Title: DataSourceContextHolder
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2022/6/6 14:42
 */
public class DataSourceContextHolder {

    public static final Logger log = LoggerFactory.getLogger(DataSourceContextHolder.class);
    private static final ThreadLocal<String> DB_HOLDER = new ThreadLocal<>();

    private DataSourceContextHolder() {
    }

    public static String getDB() {
        return (DB_HOLDER.get());
    }

    public static void setDB(String dbType) {
        log.debug("Switch to DataBase: {}", dbType);
        DB_HOLDER.set(dbType);
    }

    public static void clearDB() {
        DB_HOLDER.remove();
    }
}
